package com.li.configserve.config.interceptor;

import com.li.toolkit.constant.LogConst;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @Description：
 * @Author：LiDong
 * @Create：2020/8/17
 * @Version：1.0.0
 */
@Configuration
public class UrlConfig implements WebMvcConfigurer {

    private static final Logger logger = LoggerFactory.getLogger(UrlConfig.class);

    /**
     * 解决拦截器中bean注册不进去的问题
     * @return
     */
    @Bean
    UrllInterceptor urllInterceptor(){
        return new UrllInterceptor();
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        logger.info(LogConst.LOG_SUCCESS_PREFIX+"注册拦截器...");
        //注册TestInterceptor拦截器
        InterceptorRegistration registration = registry.addInterceptor(urllInterceptor());
        //所有路径都被拦截
        registration.addPathPatterns("/**");
        //添加不拦截路径
        registration.excludePathPatterns(
                "你的登陆路径",
                "/swagger-ui.html",
                "*.png"
        );
    }
}
